package com.project.hqshorttaxi.controller;

import com.github.pagehelper.PageHelper;
import com.project.hqshorttaxi.aop.TagLog;
import com.project.hqshorttaxi.dto.OrderParam;
import com.project.hqshorttaxi.service.OrderService;
import com.project.hqshorttaxi.util.PageInfo;
import com.project.hqshorttaxi.util.RestResult;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

@RestController
@RequestMapping("/api/order/")
public class OrderController {

    @Resource
    OrderService orderService;

    /**
     * 列表
     */
    @PostMapping("page")
    @TagLog(operation = 0, content = "查询订单列表")
    public RestResult page(@RequestBody OrderParam param) {
        PageHelper.startPage(param.getPageNum(), param.getPageSize());
        return RestResult.ok(new PageInfo<>(orderService.list(param)));
    }

    /**
     * 根据ID获取
     */
    @GetMapping("{id}")
    @TagLog(operation = 0, content = "根据ID获取订单详细信息")
    public RestResult pageById(@PathVariable Integer id) {
        return RestResult.ok(orderService.getById(id));
    }

    /**
     * 根据ID获取
     */
    @GetMapping("/plateNumber")
    public RestResult pageByPlateNumber(String plateNumber) {
        return RestResult.ok(orderService.getByPlateNumber(plateNumber));
    }
}
